from tkinter import Tk,Label
 
root = Tk()
# 180x180代表了初始化时主窗口的大小，10，10代表了初始化时窗口所在的位置
root.geometry('400x400')
root.title('窗体的布局')

'''
# 填充布局
L1=Label(root, text = 'L1', bg = 'red')
L1.pack(fill = 'y')
L2=Label(root, text = 'L2', bg = 'green')
L2.pack(fill = 'both')
L3=Label(root, text = 'L3', bg = 'blue')
L3.pack(fill = 'x')
  
# 左右布局
Label(root, text = 'L1', bg = 'red').pack(fill = 'y', side = 'left')
Label(root, text = 'L2', bg = 'green').pack(fill = 'both', side = 'right')
Label(root, text = 'L3', bg = 'blue').pack(fill = 'x', side = 'left')

 
# 绝对布局
L4 = Label(root, text = 'l4')
L4.place(x = 3, y = 3, anchor = 'nw')
''' 

# Grid 网格布局
l1 = Label(root, text = 'L1', bg = 'red')
l2 = Label(root, text = 'L2', bg = 'blue')
l3 = Label(root, text = 'L3', bg = 'green')
l4 = Label(root, text = 'L4', bg = 'yellow')
l5 = Label(root, text = 'L5', bg = 'purple')
 
l1.grid(row = 0, column = 0)
l2.grid(row = 1, column = 0)
l3.grid(row = 1, column = 1)
l4.grid(row = 2 )
l5.grid(row = 3, column = 3)

root.mainloop()
